home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / general / Block.st < prev    next >
Text File  |  2000-02-16  |  1KB  |  62 lines

  1. "---------------------------------------------------------------"
  2. "  Block CLass.
  3.  
  4.    Note how whileTrue: and whileFalse: depend upon the parser
  5.    optimizing the loops into control flow, rather than message
  6.    passing.  If this were not the case, whileTrue: would have to
  7.    be implemented using recursion, as follows:
  8.  
  9.    whileTrue: aBlock
  10.       (self value) ifFalse: [^nil].
  11.       aBlock value.
  12.       ^ self whileTrue: aBlock
  13. "
  14. "---------------------------------------------------------------"
  15.  
  16. Class Block :Object
  17. [
  18.    newProcess
  19.       ^ <primitive 141  self>
  20. |
  21.    newProcessWith: argumentArray
  22.       ^ <primitive 141  self argumentArray>
  23. |
  24.    fork
  25.       self newProcess resume.
  26.       ^ nil
  27. |
  28.    forkWith: argumentArray
  29.       (self newProcessWith: argumentArray) resume.
  30.       ^ nil
  31. |
  32.    whileTrue
  33.       ^ [self value ] whileTrue: []
  34. |
  35.    whileTrue: aBlock
  36.       ^ [ self value ] whileTrue: [ aBlock value ]
  37. |
  38.    whileFalse
  39.       ^ [ self value ] whileFalse: []
  40. |
  41.    whileFalse: aBlock
  42.       ^ [ self value ] whileFalse: [ aBlock value ]
  43. |
  44.     value
  45.       <primitive 140  0>
  46. |
  47.    value: a
  48.       <primitive 140  1>
  49. |
  50.    value: a value: b
  51.       <primitive 140  2>
  52. |
  53.    value: a value: b value: c
  54.       <primitive 140  3>
  55. |
  56.    value: a value: b value: c value: d
  57.       <primitive 140  4>
  58. |
  59.    value: a value: b value: c value: d value: e
  60.       <primitive 140  5>
  61. ]
  62.